package a;

import java.util.Iterator;

public abstract class AbstractOwnList implements OwnList {

	@Override
	public int find(String value) {
		
		if (value==null){
			throw new RuntimeException();
		}
		
		int potisition = -1;

		Iterator<String> iterator = getIterator();

		while (iterator.hasNext()) {
			potisition++;
			if (value.equals(iterator.next())) {
				return potisition;
			}
		}

		return -1;
	}

	@Override
	public void remove(String value) {
		Iterator<String> iterator = getIterator();

		while (iterator.hasNext()) {
			if (value.equals(iterator.next())) {
				iterator.remove();
				break;
			}
		}
	}

	@Override
	public void remove(int position) { // f6, f8, f5, f7
		int poS = -1;
		
		Iterator<String> iterator = getIterator();

		while (iterator.hasNext()) {
			poS++;
			iterator.next();
			if (poS == position) {
				iterator.remove();
				return;
				
			}
		}

		throw new IllegalArgumentException("Not found by " + position);
	}

	public abstract Iterator<String> getIterator();
	
	// template method

}
